{{#partial title}}编辑话题 - {{article.title}} - Rust China{{/partial}}
{{#partial page}}
  <div class="container">
    <div class="row">
      <div class="col-md-9">
        <div class="panel panel-default">
          <div class="panel-heading">
              <h3 class="panel-title">编辑话题</h3>
          </div>
          <div class="panel-body">
            <form class="form" method="post" action="/article/{{ article.id }}/edit" id="editArticleForm">
                <div class="form-horizontal">
                    <div class="form-group">
                        <div class="col-sm-2">
                            <select class="form-control" name="category">
                                {{#each categories }}
                                <option value="{{value}}" {{#if active}}selected="selected"{{/if}}>{{title}}</option>
                                {{/each}}
                            </select>
                        </div>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="title" value="{{ article.title }}" placeholder="请输入标题">
                        </div>
                    </div>
                </div>
              <div class="form-group">
                  <textarea name="content" data-provide="markdown" rows="20">{{ article.content }}</textarea>
              </div>
              <div class="form-group hidden text-danger" id="error">
              </div>
              <div class="form-group">
                  <button type="submit" class="btn btn-default">更新</button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
{{/partial}}
{{#partial footer_js}}
    <script src="{{ static_path  }}/highlight/js/highlight.pack.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
    <script src="{{ static_path  }}/js/marked.js"></script>
    <script>
     marked.setOptions({
         highlight: function (code) {
             return hljs.highlightAuto(code).value;
         }
     });
    </script>
    <script src="{{ static_path  }}/js/to-markdown.js"></script>
    <script src="{{ static_path  }}/js/bootstrap-markdown.js"></script>
    <script>
     var is_ajaxing = false;

     $('#editArticleForm').ajaxForm({
         beforeSend: function() {
             if (is_ajaxing) {
                 return false;
             }
             is_ajaxing = true;
         },
         complete: function() {
             is_ajaxing = false;
         },
         success: function(data) {
             if (data.status == 1) {
                 $('#error').text(data.message);
                 $('#error').removeClass('hidden').addClass('show');
             } else if (data.status == 302) {
                 window.location.replace(data.redirect_url);
             } else if (data.status == 0) {
                 window.location = "/article/{{article.id}}";
             }
         }
     });
    </script>
{{/partial}}
{{~> base~}}
